<!DOCTYPE html>
<html>
<head>
    <title>订单管理</title>
    <#include "/header.html">
    <style>
        .album-img {
            cursor: pointer;
        }
    </style>
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">
        <div style="margin: 10px 0">
            <form class="layui-form layui-form-pane" action="" id="searchForm">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">订单号</label>
                        <div class="layui-input-inline">
                            <input type="text" name="tradeNo" placeholder="搜索订单尾号" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">店铺名称</label>
                        <div class="layui-input-inline">
                            <input type="text" name="storeName" placeholder="搜索店铺名称" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">用户手机号</label>
                        <div class="layui-input-inline">
                            <input type="text" name="userMobile" placeholder="下单用户的手机尾号" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <button class="layui-btn layui-btn-primary layui-border-blue" lay-submit lay-filter="form-search-btn"><i class="layui-icon layui-icon-search"></i>搜索</button>
                        <button class="layui-btn layui-btn-primary" lay-submit lay-filter="form-reset-btn"><i class="layui-icon layui-icon-refresh"></i>重置</button>
                    </div>
                </div>
            </form>
        </div>

        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>
    </div>
</div>

<script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container">
    </div>
</script>

<script type="text/html" id="currentTableTradeNoTpl">
    <div class="text-blue text-lg">{{d.tradeNo}}</div>
    <div class="text-gray">{{d.createTime}}</div>
</script>

<script type="text/html" id="currentTableStoreTpl">
    {{# if(d.storeName != ''){ }}
    {{# if(d.storeAvatar != ''){ }}
    <img src="{{d.storeAvatar}}" width="45" alt="">
    {{# } else { }}
    <img src="${request.contextPath}/statics/images/avatar.png" width="45" alt="">
    {{# } }}
    <span>{{d.storeName}}</span>
    {{# } }}
</script>

<script type="text/html" id="currentTableAddressTpl">
    <span>{{d.consignee}}</span>
    <span class="margin-left-sm">{{d.mobile}}</span>
    <div>{{d.address}}</div>
</script>

<script type="text/html" id="currentTableUserTpl">
    <div>{{d.userName}}</div>
    <div>{{d.userMobile}}</div>
</script>

<script type="text/html" id="currentTableImagesTpl">
    <div id="layer-photos-view{{d.id}}">
        {{# layui.each(d.productImage, function(i, src){ }}
        <img class="album-img" layer-pid="{{i}}" layer-src="{{src}}" src="{{src}}" alt="{{i}}" width="45">
        {{# }); }}
    </div>
</script>

<script type="text/html" id="currentTableStatusTpl">
    {{# if(d.status == 71){ }}
    <span class="layui-badge layui-bg-grey">已取消</span>
    {{# } else if(d.status == 60){ }}
    <span class="layui-badge layui-bg-blue">已评价</span>
    {{# } else if(d.status == 50){ }}
    <span class="layui-badge layui-bg-blue">已送达</span>
    {{# } else if(d.status == 30){ }}
    <span class="layui-badge layui-bg-green">待送货</span>
    {{# } else if(d.status == 20){ }}
    <span class="layui-badge layui-bg-red">待付款</span>
    {{# } else if(d.status == 10){ }}
    <span class="layui-badge layui-bg-orange">备货中</span>
    {{# } else { }}
    <span class="layui-badge layui-bg-black">待接单</span>
    {{# } }}
</script>

<script type="text/html" id="currentTableBar">
    <#if shiro.hasPermission("app:order:info")>
    <a class="layui-btn layui-btn-primary layui-border-green layui-btn-xs" lay-event="edit"><i class="layui-icon layui-icon-tips"></i>查看</a>
    </#if>
</script>

<script type="text/javascript">
    var formDataId = 0;
    layui.use(['form', 'table'], function () {
        var $ = layui.jquery,
            table = layui.table;

        table.render({
            elem: '#currentTableId',
            url: serverUrl('app/order/list'),
            toolbar: false,
            // defaultToolbar: ['filter'],
            cols: [[
                {field: 'tradeNo', title: '订单编号', width: 180, templet: '#currentTableTradeNoTpl'},
                {field: 'storeName', title: '店铺名称', minWidth: 150, templet: '#currentTableStoreTpl'},
                {field: 'address', title: '送货地址', minWidth: 380, templet: '#currentTableAddressTpl'},
                {field: 'userName', title: '下单用户', minWidth: 120, templet: '#currentTableUserTpl'},
                {field: 'productImage', title: '商品图片', minWidth: 180, templet: '#currentTableImagesTpl'},
                {field: 'sumPayFee', title: '订单金额', width: 120},
                {field: 'status', title: '状态', width: 80, templet: '#currentTableStatusTpl'},
                {title: '操作', width: 100, toolbar: '#currentTableBar', align: "center"}
            ]],
            limits: [10, 25, 50],
            limit: 10,
            page: true,
            done:function(res){
                $(res.data).each(function (i, d) {
                    layer.photos({
                        photos: '#layer-photos-view'+d.id
                        ,anim: 5 //0-6的选择，指定弹出图片动画类型，默认随机（请注意，3.0之前的版本用shift参数）
                    });
                });
            }
        });

        table.on('tool(currentTableFilter)', function (obj) {
            var data = obj.data;
            if (obj.event === 'edit') {
                formDataId = data.id;
                layerOpen = layer.open({
                    title: '商店信息',
                    type: 2,
                    shade: 0.5,
                    maxmin: true,
                    area: ['95%', '90%'],
                    content: serverUrl('app/order/info.html'),
                    btn: ['确认'],
                    btnAlign: 'c',
                    yes: function(index, layero){
                        return false;
                    }
                });
            }
        });

        // 监听搜索操作
        initSearchForm('searchForm', 'currentTableId');

    });
    var layerOpen;
    //定义info子页面按钮点击事件
    var btnEvent = function () {
        $(".layui-layer-btn.layui-layer-btn-c button.layui-btn").click(function() {
            var btn = layer.getChildFrame('body', layerOpen).find($(this).attr("ref"));
            btn.click();
            return false;
        });
    };
</script>

</body>
</html>